Skip to content

new format for "package name already defined" error (+tests) #3437

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

AurelienRichez
Copy link

PR from Scala.io 2017 FLOSS spree in Lyon.

For #1589 :

This PR creates a new format of error messages for Typer.scala:1519. The new Message class is PackageNameAlreadyDefined.

Copy link
Member

@dottybot dottybot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello, and thank you for opening this PR! 🎉

All contributors have signed the CLA, thank you! ❤️

Have an awesome day! ☀️

@allanrenucci
Copy link
Contributor

@smarter scalac does not emit an error here. Is the difference intended?

@AurelienRichez AurelienRichez force-pushed the floss-spree-scala-io/package-name-already-defined branch from 7ea27f1 to 95fcac1 Compare November 7, 2017 21:10
@allanrenucci allanrenucci self-requested a review November 13, 2017 16:22
Copy link
Contributor

@allanrenucci allanrenucci left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution! Please rebase your PR

implicit val ctx: Context = ictx

assertMessageCount(1, messages)
assert(messages.head.isInstanceOf[PackageNameAlreadyDefined])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer:

val PackageNameAlreadyDefined(pkg) = messages.head
assertEquals(pkg.show, "object bar")


override def msg: String = hl"${pkg} is already defined, cannot be a package"
override def kind: String = "Syntax"
override def explanation: String =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The override keyword as well as the type ascription are a bit verbose. I would remove them

override def msg: String = hl"${pkg} is already defined, cannot be a package"
override def kind: String = "Syntax"
override def explanation: String =
"An object cannot have the same name as an existing package. Rename ${pkg} or the package with the same name."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use hl interpolator for syntax highlighting:

hl"An ${"object"} cannot have the same name as an existing ${"package"}. Rename either one of them."


case class PackageNameAlreadyDefined(pkg: Symbol)(implicit ctx: Context) extends Message(PackageNameAlreadyDefinedID) {

override def msg: String = hl"${pkg} is already defined, cannot be a package"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can syntax highlight package in this sentence:

hl"${pkg} is already defined, cannot be a ${"package"}"

@AurelienRichez AurelienRichez force-pushed the floss-spree-scala-io/package-name-already-defined branch from 95fcac1 to 8d8baba Compare November 15, 2017 17:49
@AurelienRichez
Copy link
Author

Thanks for your review ! I rebased my branch and applied the modifications.

@AurelienRichez AurelienRichez force-pushed the floss-spree-scala-io/package-name-already-defined branch from 8d8baba to a74feb6 Compare November 19, 2017 12:30
@allanrenucci allanrenucci merged commit 4fefb64 into scala:master Nov 19, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants